/*
 * @Title: 拼单支付成功
 * @Author: zhj
 * @Date:   2018-10-24
 * @Last Modified by:   zhj
 * @Last Modified time: 2018-10-24
 */
var dataInfo = {},
	template = {
		init: function() {
			Vue.use(VueLazyload, {
				preLoad: 1.3,
				error: 'http s://h5.meetao.com/img/product/init.png',
				loading: 'https://h5.meetao.com/img/product/init.png',
				attempt: 1
			});
			dataInfo.init = new Vue({
				el: '#app',
				data: {
					pageNo: 1, //页数
					pageSize: 20, //数据条数
					loading:false,//加载开光
					finished: false,
					power: false, //团长免单券显示或隐藏
					bottowPopup: { //底部弹框
						cartShow: false, //规格选择
						show: false, //保障说明
						shareShow: false, //分享弹框
						//						shareSuccess: false, //分享成功
						faceShow: false //面对面扫码
					},
					activityId:"",//拼团活动id
					GroupList: [], //火热拼商品列表
					PDinfo: {}, //拼团团员信息
					actorUserInfo: [], //参团人员信息
					notHeader: [], //未参团头像
					isPtSuccess: "", //还需拼团人数
					grouponStatus: "", //拼团状态
					button_time: "", //优惠券按钮上的天数
					more: false, //查看更多显示
					http: "", //分享页链接
					href: "", //面对面分享图片地址
					day: "",
					hr: "",
					min: "",
					sec: ""

				},
				methods: {
					init: function() { //初始化
						dataInfo.init.getgroupinfo();
						dataInfo.init.formatDuring();
						dataInfo.init.getOrderInfo();
					},
					onLoad: function() {
						this.gethotgrouplist();
					},
					closeBox: function() { //关闭优惠券弹框
						dataInfo.init.power = false;
					},
					onIndex: function() {
						location.href = "../html/PtIndex.html?GroupType=colonel_free_pt_groupon";
					},
					toCoupon: function(num) { //保障说明
						dataInfo.init.bottowPopup.show = !dataInfo.init.bottowPopup.show;
					},
					popup_close: function() { //关闭分享弹窗
						dataInfo.init.bottowPopup.shareShow = false;
					},
					popup_success: function() { //关闭分享成功弹框
						//						dataInfo.init.bottowPopup.shareSuccess = false;
						$(".shareSuccess").fadeOut();
						$(".Mask").fadeOut();
					},
					ReturnIndex: function() {
						location.href = "../html/PtIndex.html?GroupType=common_pt_groupon";
					},
					popup_face: function() {
						dataInfo.init.bottowPopup.faceShow = false;
					},
					popup_face_show: function() { //面对面分享
						dataInfo.init.bottowPopup.shareShow = false;
						dataInfo.init.bottowPopup.faceShow = true;
						dataInfo.init.onFaceImg();
						ajaxTemplate(addressTest + SERVICE.saveShareLog, function(data) {
							console,
							log(data);
							if(data.tag == 0) {

							} else {
								dataInfo.init.$toast(data.errMsg);
							}
						}, {
							userId: userId,
							grouponType: dataInfo.init.PDinfo.activityType,
							pageType: "pageGrouponOrderDetail",
							shareType: "dangmian"
						});
					},
					headerImgs: function() { //拼团头像显示更多
						if(dataInfo.init.isPtSuccess > 5) {
							dataInfo.init.more = true;
							$(".headerImg_list").addClass("headerImg_left");
						}else {
							dataInfo.init.more = false;
						}
					},
					lookmore: function() { //查看更多
						if(dataInfo.init.isPtSuccess>12){
							$(".headerImg_list").addClass("headerImg_show");
						}else{
							$(".headerImg_list").css("height","auto");
						}
						$(".moreBox").hide();
						$(".takeBox").show();
					},
					TakeUp: function() { //收起
						$(".headerImg_list").scrollTop(0);
						$(".headerImg_list").removeClass("headerImg_show");
						$(".headerImg_list").css("height","");
						$(".moreBox").show();
						$(".takeBox").hide();
					},
					getgroupinfo: function() { //支付成功获取拼团详情
						ajaxTemplate(addressTest + SERVICE.getgroupinfo, function(data) {
							if(data.tag == 0) {
								console.log(data);
//								dataInfo.init.GroupList = data.data.result.GroupList;
								dataInfo.init.PDinfo = data.data.result.PDinfo["0"];
								dataInfo.init.isPtSuccess = dataInfo.init.PDinfo.limitActorNum - dataInfo.init.PDinfo.realActorNum;
								dataInfo.init.grouponStatus = dataInfo.init.PDinfo.grouponStatus;
								groupId = dataInfo.init.PDinfo.groupId;
								virtualgoodsID = dataInfo.init.PDinfo.virtualGoodsCode;
								dataInfo.init.activityId = data.data.result.PDinfo["0"].activityId;
								activityId = data.data.result.PDinfo["0"].activityId;//全局拼团活动id
								
								fullPrice = ((data.data.result.PDinfo["0"].oldPrice) * 1000000 - (data.data.result.PDinfo["0"].activityPrice) * 1000000) / 1000000;//拼团分享产品满减金额
								goodsName = data.data.result.PDinfo["0"].goodsName;//拼团分享产品名称
								isPtSuccess = dataInfo.init.isPtSuccess; // 拼团分享还需参团人数
								sellingPointsDesc = data.data.result.PDinfo["0"].sellingPointsDesc;//拼团分享产品描述
								imgUrl = data.data.result.PDinfo["0"].imgUrl;//拼团分享产品图片
								GroupType = data.data.result.PDinfo["0"].activityType;//拼团类型
								
								dataInfo.init.join_people();
								dataInfo.init.headerImgs();
								if(data.data.result.PDinfo["0"].actorUserInfo == undefined) {//参团人员信息
									dataInfo.init.actorUserInfo = [];
								} else {
									dataInfo.init.actorUserInfo = JSON.parse(data.data.result.PDinfo["0"].actorUserInfo);
								}
								if(dataInfo.init.PDinfo.starterHeadImageUrl == "") {
									dataInfo.init.PDinfo.starterHeadImageUrl = "../img/PtPaySuccess/default-header.png";
								};
								for(var i = 0; i < dataInfo.init.actorUserInfo.length; i++) {
									if(dataInfo.init.actorUserInfo[i].headImageUrl == "") {
										dataInfo.init.actorUserInfo[i].headImageUrl = "../img/PtPaySuccess/default-header.png";
									}
								};
								if(dataInfo.init.PDinfo.grouponStatus == 1) { //判断能否获得团长免单券
									dataInfo.init.notHeader = [];
									ajaxTemplate(addressTest + SERVICE.checkFirstAndSend, function(data) {
										if(data.data.result.isSendCoupon == "y") {
											dataInfo.init.button_time = data.data.result.expireDays;
											dataInfo.init.power = true;
										} else {
											dataInfo.init.power = false;
										}
									}, {
										userId: userId,
										grouponOrderId: getQueryString("groupId")
									});
								} else {
									for(var i = 0; i < dataInfo.init.isPtSuccess; i++) {
										dataInfo.init.notHeader[i] = i;
									}
								}
							} else {}
						}, {
							groupId: getQueryString("groupId"), //拼团id
						});
					},
					gethotgrouplist: function() {//获取火热拼列表
						ajaxTemplate(addressTest + SERVICE.gethotgrouplist, function(data) {
							if(data.tag == 0){
								dataInfo.init.GroupList = JSON.parse(JSON.stringify(dataInfo.init.GroupList.concat(data.data.result)));
								if(data.data.result.length < dataInfo.init.pageSize){
									dataInfo.init.finished = true;
								}else{
									 dataInfo.init.finished = false;
								}
								dataInfo.init.loading = false;
							}else{
								dataInfo.init.$toast(data.errMsg);
							}
							
						}, {
							pageNo: dataInfo.init.pageNo++,
							pageSize: dataInfo.init.pageSize
						});
					},
					getOrderInfo: function() { //获取订单数据
						ajaxTemplate(addressUrl + SERVICE.getOrderInfo, function(data) {
							if(data.tag == 0) {} else {
								dataInfo.init.$toast(data.errMsg);
							};
						}, {
							userId: userId,
							orderId: getQueryString("orderId")
						});
					},
					sharePopup: function() {
						dataInfo.init.bottowPopup.shareShow = !dataInfo.init.bottowPopup.shareShow;
					},
					//跳转拼团订单详情封装方便管理
					jumpPtOrderDetails: function() {
						location.href = "../html/PtOrderDetails.html?orderId=" + getQueryString("orderId");
					},
					timeFormat: function(param) { //小于10的格式化函数
						return param < 10 ? '0' + param : param;
					},
					formatDuring: function() { //倒计时
						// 获取当前时间，同时得到活动结束时间数组
						var newTime = new Date().getTime();
						var endTime = dataInfo.init.PDinfo.endTime; //结束时间dataInfo.init.PDinfo["0"].endTime
						var obj = null;
						if(endTime - newTime > 0) {
							var time = (endTime - newTime) / 1000;
							// 获取天、时、分、秒
							dataInfo.init.day = parseInt(time / (60 * 60 * 24));
							dataInfo.init.hr = parseInt(time % (60 * 60 * 24) / 3600);
							dataInfo.init.min = parseInt(time % (60 * 60 * 24) % 3600 / 60);
							dataInfo.init.sec = parseInt(time % (60 * 60 * 24) % 3600 % 60);
							dataInfo.init.day = dataInfo.init.timeFormat(dataInfo.init.day);
							dataInfo.init.min = dataInfo.init.timeFormat(dataInfo.init.min);
							dataInfo.init.sec = dataInfo.init.timeFormat(dataInfo.init.sec);
							if(dataInfo.init.day != 0) {
								dataInfo.init.hr = dataInfo.init.timeFormat(dataInfo.init.hr + dataInfo.init.day * 24);
							} else {
								dataInfo.init.hr = dataInfo.init.timeFormat(dataInfo.init.hr);
							}
						} else { //活动已结束，全部设置为'00'
							dataInfo.init.day = "00",
								dataInfo.init.hr = "00",
								dataInfo.init.min = "00",
								dataInfo.init.sec = "00";
						};
						setTimeout(dataInfo.init.formatDuring, 1000);
					},
					join_people: function() { //参与人数截取位数
						if(dataInfo.init.GroupList != "") {
							if(dataInfo.init.GroupList.length > 0) {
								for(var i = 0; i < dataInfo.init.GroupList.length; i++) {
									if(dataInfo.init.GroupList[i].showActorNum >= 10000) {
										dataInfo.init.GroupList[i].showActorNum = (dataInfo.init.GroupList[i].showActorNum / 10000).toFixed(1) + "万";
									}
								}
							}
						}
					},
					onFaceImg: function() {//面对面扫码图片地址
						dataInfo.init.http = window.location.href.split("/html/")[0] + "/html/PtShare.html?virtualgoodsID=" + dataInfo.init.PDinfo.virtualGoodsCode + "&activityId=" + dataInfo.init.activityId + "&groupId=" + groupId;
						dataInfo.init.href = 'https://testsvr.meetao.com/api/groupon/common/makeQRCode?content=' + escape(dataInfo.init.http) + '&imgWidth=200&imgHeight=200&imgFormat=png';
						$(".ewm_img").attr("src",dataInfo.init.href);
					}
				}
			});
			dataInfo.init.init();
		}
	};
template.init();